home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / program / rcs5ap1s.lzh / RCSCLEAN.SH < prev    next >
Linux/UNIX/POSIX Shell Script  |  1991-01-10  |  2KB  |  108 lines

  1. #! /bin/sh
  2. #
  3. # rcsclean - remove working files that are copies of the latest RCS revision
  4.  
  5. #    $Id: rcsclean.sh,v 1.7 90/11/13 15:46:17 hammer Exp $
  6.  
  7. # This program removes working files which are copies of the latest
  8. # revision on the default branch of the corresponding RCS files.
  9. # For each file given, rcsclean performs a co operation for the latest
  10. # revision on the default branch, and compares
  11. # the result with the working file. If the two are identical,
  12. # the working file is deleted.
  13. #
  14. # A typical application in a Makefile would be:
  15. # clean:;       rm *.o; rcsclean *.c *.o
  16. #
  17. # Limitation: This program doesn't work if given the name of
  18. # an RCS file rather than the name of the working file.
  19.  
  20. PATH=/usr/local/bin:/bin:/usr/bin:/usr/ucb:$PATH
  21. export PATH
  22.  
  23. usage='rcsclean: usage: rcsclean file ...'
  24.  
  25. case $1 in
  26. 0) echo >&2 "$usage"; exit 2
  27. esac
  28.  
  29. _='
  30. '
  31. IFS=$_
  32.  
  33. rcs=rcs
  34. rcsdiff=rcsdiff
  35.  
  36. for i
  37. do
  38.     case $i in
  39.     -*)
  40.         case $i in
  41.         -[qr]*) rcs=$rcs$_$i
  42.         esac
  43.         rcsdiff=$rcsdiff$_$i
  44.         shift;;
  45.     *) break
  46.     esac
  47. done
  48.  
  49. case $# in
  50. 0)
  51.     files=
  52.     for file in .* *
  53.     do
  54.         case $file in
  55.         *,v | . | ..) ;;
  56.         [-+]* | *$_*) echo >&2 "rcsclean: $file: strange file name"; exit 2;;
  57.         *)
  58.             case $file in
  59.             '*' | '.*') [ -f "$file" ] || continue
  60.             esac
  61.             files=$files$_$file
  62.         esac
  63.     done
  64.     case $files in
  65.     ?*) set $files
  66.     esac;;
  67. *)
  68.     case $* in
  69.     *$_*) echo >&2 'rcsclean: newline in arguments'; exit 2
  70.     esac
  71. esac
  72.  
  73. remove=
  74. status=0
  75.  
  76. for i
  77. do
  78.     case $i in
  79.     -*)
  80.         case $i in
  81.         -[qr]*) rcs=$rcs$_$i
  82.         esac
  83.         rcsdiff=$rcsdiff$_$i;;
  84.     *,v)
  85.         echo >&2 "rcsclean: $i: cannot handle RCS file name"; exit 2;;
  86.     *)
  87.         $rcsdiff -q $i >/dev/null 2>&1
  88.         case $? in
  89.         # Ignore rcsdiff trouble (usually files that are not under RCS).
  90.         0) remove=$remove$_$i;;
  91.         1)
  92.             echo >&2 "rcsclean: $i: " || exit
  93.             status=1
  94.         esac
  95.     esac
  96. done
  97.  
  98. case $remove in
  99. ?*)
  100.     unlock=`rlog -L -R -l${LOGNAME-$USER} $remove` &&
  101.     case $unlock in
  102.     ?*) $rcs -u $unlock
  103.     esac &&
  104.     rm -f $remove || status=2
  105. esac
  106.  
  107. exit $status
  108.